<template>
  <div class="hotJob">
    <table-box :title="titleType">
      <template v-slot:more>
        <em @mouseover="showCityBox" @mouseleave="hideCityBox">{{titleMore}} 
          <span class="el-icon-arrow-down"></span>
            <div class="cityBox">
              <span class="cities" v-for="items in cityBoxData" :key="items.id" @click="selectCity">
               {{items.id}}
              </span>
            </div>
        </em>
      </template>
      <template v-slot:type-span>
        <span v-for="(items, idx) in positionType" :key="idx" @click="sliceData" class="selectPosition">
          {{items.title}}
        </span>
        <!-- <type-span v-for="(items, idx) in positionType" :key="idx" @click="sliceData">
          {{items.title}}
        </type-span> -->
      </template>
      <template v-slot:item-list>
        <item-list v-for="(items, idx) in positionDetailFilter" :key="idx" :cont="items"></item-list>
      </template>
    </table-box>
    <p class="loadMore">加载更多</p>
  </div>
</template>
<script>

// 引入自定义的span组件
import TypeSpan from "@/components/returnee/typeSpan.vue"
// 引入自定义的item组件
import ItemList from "@/components/returnee/itemList.vue"


// 引入tableBox组件，该组件可被复用
import TableBox from "@/components/returnee/tableBox.vue"
// 引入获取职位类型的接口
import { getReturneePositionType } from "@/api"
// 引入获取热门职位详细数据的接口
import { getReturneeHotPositionDetails } from "@/api"
// 引入获取热门城市接口
import { getReturneeHotCity } from '@/api'
export default {
  name: "returneehotjob",
  components: {
    TableBox,
    TypeSpan,
    ItemList
  },
  data() {
    return {
      titleMore: "全国",
      titleType: "热门岗位",
      positionType: [],
      positionDetail: [],
      positionDetailFilter: [],
      cityBox: "",
      cityBoxData: ""
    }
  },
  methods: {
    selectCity(event){
      
    this.positionDetailFilter = this.positionDetail.filter((val)=>{
        return  val.companyDddress.includes(event.target.innerText);
      });
    },

    showCityBox(){
      this.cityBox.style.display = "block";
    },
    hideCityBox(){
      this.cityBox.style.display = "none";
    },
    // 测试截取数据
    sliceData(){
      // console.log(1111);
    }
  },
  mounted() {
    this.cityBox = document.querySelector(".cityBox");
    getReturneePositionType().then((res)=>{
      this.positionType = res.data.data;
    });
    getReturneeHotCity().then((res)=>{
      this.cityBoxData = res.data.data;
    });
    getReturneeHotPositionDetails().then((res)=>{
      const datas = res.data.data;
      datas.forEach(val => {
        val.district.forEach((items)=>{
          items.children.forEach((singleData)=>{
            this.positionDetail.push(singleData);
            this.positionDetailFilter.push(singleData);
          });
        });
      });
    });
  }
}
</script>
<style lang="less" scoped>
  .hotJob{
    width: 100%;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
      .selectPosition{
        display: inline-block;
        width: 96px;
        height: 34px;
        text-align: center;
        line-height: 34px;
        background-color: #fff;
        border-radius: 6px;
        margin: 6px;
        font-size: 14px;
        cursor: pointer;
  }
      em{
        color: #5dd5c8;
        font-size: 12px;
        cursor: pointer;
        position: relative;
          .cityBox{
            width: 440px;
            // height: 300px;
            background-color: #fff;
            position: absolute;
            left: 18px;
            top: 14px;
            display: none;
              .cities{
                display: inline-block;
                width: 100px;
                height: 40px;
                text-align: center;
                line-height: 40px;
                background-color: #fff;
                color: #000;
                margin: 5px;
                  &:hover{
                    color: #5dd5c8;
                  }
              }
          }
      }
      .loadMore{
        background-color: #5dd5c8;
        width: 220px;
        height: 34px;
        text-align: center;
        line-height: 34px;
        margin-top: 10px;
        border-radius: 4px;
        color: #fff;
      }
  }
</style>